package pl.edu.pw.perg.compinfodb.datamodel;

import java.util.Vector;

import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

public class FlexibleTableColumnModel extends DefaultTableColumnModel {
	private static TableCellRenderer renderer ;
	private String[] columnNames;
	
	public FlexibleTableColumnModel(TableCellRenderer tcr){
		renderer = tcr;
	}
	
	public void setColumnNames(String[] columnNames){
		this.columnNames = columnNames;
		Vector<TableColumn> tcs = new Vector<TableColumn>();
		for (int i = 0; i < columnNames.length; i++) {
			TableColumn tc = new TableColumn();
			tc.setCellRenderer(renderer);
			tc.setModelIndex(i);
			tc.setHeaderValue(columnNames[i]);
			tcs.add(tc);
		}
		
		super.tableColumns = tcs; 
	}
	
	public String[] getColumnNames(){
		return columnNames;
	}

	public static TableCellRenderer getRenderer() {
		return renderer;
	}

	public static void setRenderer(TableCellRenderer renderer) {
		FlexibleTableColumnModel.renderer = renderer;
	}
}
